﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Worktool.CODE_Chris.DataSourceHelpers;
using Worktool.CODE_Chris.SQL_DATA;

namespace Worktool
{
    public partial class ReportRooms : Form
    {
        private SQL sql;
        private ReportRoomsHelper helper;
        private Boolean isInit = true;

        public ReportRooms()
        {
            InitializeComponent();
            this.Text = "Rooms: " + Login.currentDBName;
            init();
        }

        private void init()
        {
            sql = new SQL();
            helper = new ReportRoomsHelper(reportViewer1, this);

            fillElementsInit();

            fillTablesInit();

            isInit = false;

            comboBox1.Text = comboBox1.Items[1].ToString();
        }

        #region Init
        private void fillTablesInit()
        {
            try
            {
                helper.getData1();
            }
            catch (Exception e)
            {

            }
        }

        private void fillElementsInit()
        {
            try
            {
                String[,] areas = sql.receiveSQL("SELECT Venue FROM STAMMDATEN_areas");
                comboBox1.Items.Clear();
                comboBox1.DropDownHeight = 300;
                comboBox1.Items.Add("");
                for (int a = 0; a < areas.GetLength(1); a++)
                {
                    comboBox1.Items.Add(areas[0, a]);
                }
                comboBox1.Refresh();
            }
            catch (Exception e)
            {

            }
        }
        #endregion

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!isInit)
            {
                try
                {
                    ReportParameter[] parameters = new ReportParameter[1];
                    parameters[0] = new ReportParameter("uberschrift", comboBox1.Text);
                    reportViewer1.LocalReport.SetParameters(parameters);
                    if (helper.getTable1() != null) helper.getTable1().DefaultView.RowFilter = string.Format("Venue LIKE '{0}'", Login.setFilterCharacters(comboBox1.Text));
                    reportViewer1.RefreshReport();
                }
                catch (Exception ex)
                {
                }
            }
        }
    }
}
